import { resolve } from "url"
import * as RouteApi from "@/api/route/route.js" 
import Socket from "@/utils/socket/socket.js"
import config from "@/core/config/index.js"
import user from "./user.js"

export default {
    namespaced: true, 
	state:{
		speaker:null,
		playing:true
	},
	actions:{
		initial({state}){
			state.speaker = my.createInnerAudioContext()
			state.speaker.onPlay(() => {
				state.playing = true
			})
			state.speaker.onEnded(() => {
				state.playing = false
			})
		},
		speak({state,dispatch},src){
			if(state.speaker === null){
				dispatch("initial")
			}
			if(state.playing){
				state.speaker.stop()
			}
			state.speaker.src = src
			state.speaker.play()
		},
		
		
	},
	
}